var toolOp = -1;
var layer;
var pointTemp;
var tempid;
var tubiaodata;
//显示右键菜单
var RClick_entity = null;
var element;
var table;
// var objectLiuzhou=loadJsonData("柳州", "../data/lz_84.json",
//     Cesium.Color.CYAN, Cesium.Color.CYAN.withAlpha(0.1), 3);

$(document).ready(function () {
    layui.use(['layer'], function () {
        layer = layui.layer;
    });
    layui.use(['table'], function () {
        table = layui.table;
    });
    layui.use('element', function () {
        element = layui.element;

    });
    layui.use(['form'], function () {
        var form = layui.form;
        //监听提交
        form.on('submit(edityfq)', function (data) {

            var pointTemp = RClick_entity.id.position.getValue();
            var point = CartesianToDegrees(pointTemp);
            var geom = 'POINT(' + point[0] + ' ' + point[1] + ')';


            var yfq = {
                id: tempid,
                szXian: data.field.szXian,
                szXiang: data.field.szXiang,
                address: data.field.address,
                zhType: data.field.zhType,
                wxH: data.field.wxH,
                wxJ: data.field.wxJ,
                wxR: data.field.wxR,
                azd: data.field.azd,
                wfYa: data.field.wfYa,
                zhMbk: data.field.zhMbk,
                bxMbk: data.field.bxMbk,
                cunFzr: data.field.cunFzr,
                tel1: data.field.tel1,
                zhenFzr: data.field.zhenFzr,
                tel2: data.field.tel2,
                xianFzr: data.field.xianFzr,
                tel3: data.field.tel3,
                bz: data.field.bz,
                geom: geom
            }
            var attaIds = getAttachmentIds();

            var yfqdata = JSON.stringify(yfq);
            var attas = JSON.stringify(attaIds);


            var hr = updateZhyfq(yfqdata, attas);
            if (hr > 0) {
                tempid = hr;
                layer.msg('修改成功!', {
                    icon: 1,
                    time: 1000 //1.5秒关闭（如果不配置，默认是3秒）
                }, function () {


                    hideMapRMenu();
                    RClick_entity = null;


                    layer.closeAll();
                });
            }
            else {
                layer.msg("修改失败！");
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
    layui.use(['form'], function () {
        var form = layui.form;

        //监听提交
        form.on('submit(addyhd)', function (data) {


            var pointTemp = RClick_entity.id.position.getValue();
            var point = CartesianToDegrees(pointTemp);
            var geom = 'POINT(' + point[0] + ' ' + point[1] + ')';

            var yhd = {
                szXian: data.field.szXian,
                szXiang: data.field.szXiang,
                szCun: data.field.szCun,
                szTun: data.field.szTun,
                zdMc: data.field.zdMc,
                zdWz: data.field.zdWz,
                yhdType: data.field.yhdType,
                fxDate: data.field.fxDate,
                ghFl: data.field.ghFl,
                yfYs: data.field.yfYs,
                yfYy: data.field.yfYy,
                wxDx: data.field.wxDx,
                wxR: data.field.wxR,
                wxCz: data.field.wxCz,
                xqJb: data.field.xqJb,
                bz: data.field.bz,
                jcy: data.field.jcy,
                tel1: data.field.tel1,
                cunFzr: data.field.cunFzr,
                tel2: data.field.tel2,
                xiangFzr: data.field.xiangFzr,
                tel3: data.field.tel3,
                xianFzr: data.field.xianFzr,
                tel4: data.field.tel4,
                geom: geom
            }
            var attaIds = getyhdAttachmentIds();

            var yhddata = JSON.stringify(yhd);
            var attas = JSON.stringify(attaIds);
            var hr = insertZhyhd(yhddata, attas);
            if (hr > 0) {
                tempid = hr;
                DrawBillboardByDegrees(data.field.zdMc, point[0], point[1], "./static/images/yhd.png",
                    data.field.zdWz, QResultLayerYHD, "yhd_" + hr);
                entities.removeById(RClick_entity.id.id);

                layer.msg('保存成功!', {
                    icon: 1,
                    time: 1000 //1.5秒关闭（如果不配置，默认是3秒）
                }, function () {
                    layer.closeAll();
                });

            }

            else {
                layer.msg("保存失败！");
            }

            hideMapRMenu();
            RClick_entity = null;
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


    });
    layui.use(['form'], function () {
        var form = layui.form;
        //监听提交
        form.on('submit(edityhd)', function (data) {


            var pointTemp = RClick_entity.id.position.getValue();
            var point = CartesianToDegrees(pointTemp);
            var geom = 'POINT(' + point[0] + ' ' + point[1] + ')';


            var yhd = {
                id: tempid,
                szXian: data.field.szXian,
                szXiang: data.field.szXiang,
                szCun: data.field.szCun,
                szTun: data.field.szTun,
                zdMc: data.field.zdMc,
                zdWz: data.field.zdWz,
                yhdType: data.field.yhdType,
                fxDate: data.field.fxDate,
                ghFl: data.field.ghFl,
                yfYs: data.field.yfYs,
                yfYy: data.field.yfYy,
                wxDx: data.field.wxDx,
                wxR: data.field.wxR,
                wxCz: data.field.wxCz,
                xqJb: data.field.xqJb,
                bz: data.field.bz,
                jcy: data.field.jcy,
                tel1: data.field.tel1,
                cunFzr: data.field.cunFzr,
                tel2: data.field.tel2,
                xiangFzr: data.field.xiangFzr,
                tel3: data.field.tel3,
                xianFzr: data.field.xianFzr,
                tel4: data.field.tel4,
                geom: geom
            }
            var attaIds = getyhdAttachmentIds();

            var yhddata = JSON.stringify(yhd);
            var attas = JSON.stringify(attaIds);
            var hr = updateZhyhd(yhddata, attas);
            if (hr > 0) {
                tempid = hr;
                layer.msg('修改成功!', {
                    icon: 1,
                    time: 1000 //1.5秒关闭（如果不配置，默认是3秒）
                }, function () {
                    layer.closeAll();
                });
            }
            else {
                layer.msg("修改失败！");
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#uploadPic' //绑定元素
            , url: '/upload/uploadFile'//上传接口
            , accept: 'images',
            done: function (res) {
                layui.use('layer', function () {
                    $("#uploaded-files").append(
                        $("<tr id='option" + res.list[0].id + "' data-id='" + res.list[0].id + "'/>")
                            .append($('<td/>').html("<img class='layui-upload-img' id='pic" + res.list[0].id + "' alt='" + res.list[0].fileName + "' src='/upload/downloadFile/" + res.list[0].id + "'  >"))
                            .append($('<td/>').html("<a onclick='deleteRow(" + res.list[0].id + ")'>删除</a>"))
                    );

                });
            }, before: function (obj) {

            }
            , error: function (err) {

                console.log(err)
                //请求异常回调
            }
        });
    });
    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#yhd-uploadPic' //绑定元素
            , url: '/upload/uploadFile'//上传接口
            , accept: 'images',
            done: function (res) {
                layui.use('layer', function () {
                    $("#yhd-uploaded-files").append(
                        $("<tr id='option" + res.list[0].id + "' data-id='" + res.list[0].id + "'/>")
                            .append($('<td/>').html("<img class='layui-upload-img' id='pic" + res.list[0].id + "' alt='" + res.list[0].fileName + "' src='/upload/downloadFile/" + res.list[0].id + "'  >"))
                            .append($('<td/>').html("<a onclick='deleteRow(" + res.list[0].id + ")'>删除</a>"))
                    );

                });
            }, before: function (obj) {

            }
            , error: function (err) {

                console.log(err)
                //请求异常回调
            }
        });
    });

    $("#dropmenu").change(function () {
        var data = gettubiaodata();
        tianchongtubiao(data);
    });


});


function showLiuzZhouAll() {
    // viewer.flyTo(objectLiuzhou);
    viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(109.407908, 24.226236, 4000),
        orientation: {
            pitch: Cesium.Math.toRadians(-20),    // default value (looking down)
            roll: 0.0                             // default value
        },
        duration: 2
    });
}
function PanOp() {
    toolOp = 0;
}
function drawPoint() {
    drawControl.startDraw({type: "billboard", style: {image: "./static/images/mark.png"}});
    toolOp = 1;
}

function drawPolyline() {
    drawControl.startDraw({type: "polyline", terrain: !1, style: {color: G_fillcolor, width: G_DrawPan}});
    toolOp = 2;
}

function drawPolygon() {
    drawControl.startDraw({
        type: "polygon",
        style: {
            color: G_fillcolor,
            outline: !0,
            outlineColor: G_framecolor,
            perPositionHeight: !1,
            outlineWidth: G_DrawPan,
            opacity: G_Alpha
        }
    });
    toolOp = 3;
}

function deleteAllLS() {
    drawControl.deleteAll();
    measureSurface.clearMeasure();

    if (PullframeOverLay != null)
        drawControl.deleteEntity(PullframeOverLay);
    if (OpenFileOverlay != null)
        entities.removeById(OpenFileOverlay.id);

    for (let i = 0; i < QResultLayerQ.length; i++) {
        entities.removeById(QResultLayerQ[i].id);
    }
    QResultLayerQ.length = 0;

    toolOp = -1;


}

function measuerLength() {
    measureSurface.measuerLength({terrain: !0});
    toolOp = 10;
}

//测量--面积
function measureArea() {
    measureSurface.measureArea();
    toolOp = 11;
};

//测量--高差(详细)
function measureHeight() {
    measureSurface.measureHeight({isSuper: !0})
};

//量测--方位
function BearingAngle() {
    measureSurface.BearingAngle({});
    toolOp = 12;
};
layui.use('tree', function () {
    var tree = layui.tree;
    var yhdyear = [];
    var yfqyear = [];
    $.ajax({
        url: "/geoZhyfq/getYfqYear",
        type: 'GET',
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    yfqyear.push({
                        title: data[i] + "年度易发区",
                        id: data[i] + "年度易发区",
                    });

                }
            }

        },
        error: function () {

        },
    });

    $.ajax({
        url: "/geoZhyhd/getYhdYear",
        type: 'GET',
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    yhdyear.push({
                        title: data[i] + "年度隐患点",
                        id: data[i] + "年度隐患点",
                    });

                }
            }
        },
        error: function () {

        },
    });


    //渲染
    var inst1 = tree.render({
        elem: '#tree', //绑定元素
        showCheckbox: true,
        showLine: false,
        onlyIconControl: false,
        id: 'treeid',
        data: [
            {title: '乡镇边界'}, {title: '全景数据点'}, {title: '倾斜数据1'}, {title: '倾斜数据2'}, {title: '倾斜数据3'},
            {
                title: '群测群防点',
                id: 'yfq',
                children: [{
                    title: '群众上报' //二级菜单
                }, {
                    title: '日常巡查' //二级菜单
                }],
            },

            {
                title: '地质灾害易发区',
                id: 'yfq',
                children: yfqyear,
            },
            {title: '地质灾害隐患点', children: yhdyear, id: 'yhd'}],
        oncheck: function (obj) {

            var checkdata = {checked: obj.checked}
            if (obj.data.title == '乡镇边界') {
                showLayerMap(checkdata, 0, "0");
            }
            if (obj.data.title == "地质灾害易发区") {
                showLayerMap(checkdata, 1, "1970");
            }

            if (obj.data.title == "地质灾害隐患点") {
                showLayerMap(checkdata, 2, "1970");
            }
            if (obj.data.title == "全景数据点") {
                showLayerMap(checkdata, 6, "0");
            }


            if (obj.data.title.indexOf("年度易发区") != -1) {
                showLayerMap(checkdata, 1, obj.data.title.substring(0, 4));
            }
            if (obj.data.title.indexOf("年度隐患点") != -1) {
                showLayerMap(checkdata, 2, obj.data.title.substring(0, 4));
            }


            if (obj.data.title == "群测群防点") {
                showLayerMap(checkdata, 3, "0");
            }

            if (obj.data.title == "倾斜数据1") {
                showLayerMap(checkdata, 10, "0");
            }

            if (obj.data.title == "倾斜数据2") {
                showLayerMap(checkdata, 11, "0");
            }

            if (obj.data.title == "倾斜数据3") {
                showLayerMap(checkdata, 12, "0");
            }


            if (obj.data.title == "群众上报") {
                showLayerMap(checkdata, 4, "0");
            }

            if (obj.data.title == "日常巡查") {
                showLayerMap(checkdata, 5, "0");
            }
        }
    });


});


//查询—拉框
var PullframeOverLay = null;
function QueryByPullframe() {
    if (PullframeOverLay != null)
        drawControl.deleteEntity(PullframeOverLay);
    if (OpenFileOverlay != null)
        entities.removeById(OpenFileOverlay.id);
    for (let i = 0; i < QResultLayerQ.length; i++) {
        entities.removeById(QResultLayerQ[i].id);
    }
    QResultLayerQ.length = 0;

    drawControl.startDraw({
        type: "rectangle",
        style: {
            color: "#E2EDE2",
            outline: !0,
            outlineColor: "#ff2b1d",
            perPositionHeight: !1,
            outlineWidth: 5,
            opacity: 0.2
        }
    });
    toolOp = 20;
}

//查询—导入
var OpenFileOverlay = null;
var openFile = function (event) {

    drawControl.deleteAll();
    measureSurface.clearMeasure();

    if (PullframeOverLay != null)
        drawControl.deleteEntity(PullframeOverLay);
    if (OpenFileOverlay != null)
        entities.removeById(OpenFileOverlay.id);

    for (let i = 0; i < QResultLayerQ.length; i++) {
        entities.removeById(QResultLayerQ[i].id);
    }
    QResultLayerQ.length = 0;

    var points = [];
    var CesiumPoints = [];
    var input = event.target;
    var reader = new FileReader();
    reader.onload = function () {
        if (reader.result) {
            var allstr = reader.result;
            var strList = allstr.split('\n');
            var coordType = null;

            event.target.value = "";

            for (var i = 0; i < strList.length; i++) {
                if (i == 0) {
                    coordType = strList[i];
                    continue;
                }
                var lineStr = strList[i];
                var temp = lineStr.split(',');
                if (temp.length != 2) {
                    layer.msg("第" + (i + 1) + "行出现错误！");
                    return;
                }
                if (!myIsNaN(parseFloat(temp[0])) || !myIsNaN(parseFloat(temp[1]))) {
                    layer.msg("第" + (i + 1) + "行出现非数值型字符！");
                    return;
                }

                if (coordType.indexOf('直角') > -1) {
                    // points.push(new BMap.Point(parseFloat(temp[1]),parseFloat(temp[0])));
                    points.push({lng: parseFloat(temp[1]), lat: parseFloat(temp[0])});
                }
                else if (coordType.indexOf('地理') > -1) {
                    // points.push(new BMap.Point(parseFloat(temp[0]),parseFloat(temp[1])));
                    points.push({lng: parseFloat(temp[0]), lat: parseFloat(temp[1])});
                    CesiumPoints.push(Cesium.Cartesian3.fromDegrees(parseFloat(temp[0]), parseFloat(temp[1])));
                }

                else {
                    layer.msg("坐标格式有误！");
                    return;
                }
            }

            if (coordType.indexOf('直角') > -1) {
                var tempPoint = [];
                var tempCesiumPoint = [];
                for (var nP = 0; nP < points.length; nP++) {
                    var point = Xian80_To_WGS84(parseFloat(points[nP].lng), parseFloat(points[nP].lat), 0);
                    // tempPoint.push(new BMap.Point(parseFloat(point.x),parseFloat(point.y)));
                    tempPoint.push({lng: parseFloat(point.x), lat: parseFloat(point.y)});
                    tempCesiumPoint.push(Cesium.Cartesian3.fromDegrees(parseFloat(point.x), parseFloat(point.y)));
                }
                points = tempPoint;
                CesiumPoints = tempCesiumPoint;
            } else {

            }

            //绘制
            var pointTemp = [];
            for (let j = 0; j < points.length; j++) {
                var point = {x: points[j].lng, y: points[j].lat};
                pointTemp.push(point);
            }
            var entity = DrawPloygon("查询", pointTemp, Cesium.Color.WHITE.withAlpha(0.3), "", "cx_-1");
            OpenFileOverlay = entity;
            //定位
            var BoundingSphere = new Cesium.BoundingSphere.fromPoints(CesiumPoints);
            scene.camera.flyToBoundingSphere(BoundingSphere);

            //查询
            let strPolygon = "POLYGON((";//起始点要一致
            for (let i = 0; i < points.length; i++) {
                strPolygon += points[i].lng + " " + points[i].lat + ",";
            }
            strPolygon += points[0].lng + " " + points[0].lat;//添加第一点
            strPolygon += "))";
            getQContains(strPolygon);
        }

    };
    reader.readAsText(input.files[0]);

    toolOp = 21;
};

function getQContains(strPolygon) {
    layer.open({
        type: 1,
        title: '拉框查询',
        shade: false,
        offset: 'rb',
        maxmin: true,
        closeBtn: 1,
        area: ['100%', '48%'],
        content: $('#fenxitable'), cancel: function () {
            deleteAllLS();
        }
    });
    document.getElementById("resultdiv").style.display = "block";
    document.getElementById("searchdiv").style.display = "none"; //隐藏

    var loading = gis_ContainsZhyfq(strPolygon);
    gis_ContainsZhyhd(strPolygon, loading);
}

function showLayerMap(self, type, nd) {
    if (type == 0) {//乡镇行政区划
        if (self.checked) {
            var hr = getAllXzqxian({});
            showQresult(hr, true, type);
        } else {
            for (let i = 0; i < QResultLayerXZQ.length; i++) {
                entities.removeById(QResultLayerXZQ[i].id);
            }
            QResultLayerXZQ.length = 0;
        }
    } else if (type == 1) {//地质灾害易发区
        if (self.checked) {
            getZhyfqByNd(nd, type, 2);
        } else {
            for (let i = 0; i < QResultLayerYFQ.length; i++) {
                if (nd != "1970" && QResultLayerYFQ[i].name.substring(0, 4) == nd) {
                    entities.removeById(QResultLayerYFQ[i].id);
                }

            }


            // QResultLayerYFQ.length=0;
        }


    } else if (type == 2) {//地质隐患点
        if (self.checked) {
            getZhyhdByNd(nd, type, 2);
        } else {
            for (let i = 0; i < QResultLayerYHD.length; i++) {
                if (nd != "1970" && QResultLayerYHD[i].name.substring(0, 4) == nd) {
                    entities.removeById(QResultLayerYHD[i].id);
                }
            }
            // QResultLayerYHD.length=0;
        }
    } else if (type == 6) {//全景数据点

        if (self.checked) {
            var hr = GetAllQJ({});
            showQresult(hr, true, type);

        } else {
            for (let i = 0; i < QResultLayerQJ.length; i++) {
                entities.removeById(QResultLayerQJ[i].id);
            }

        }
    } else if (type == 3) {//群测群防点
        if (self.checked) {
            var hr = getAllRecord();
            showQresult(hr, true, type);

        } else {
            for (let i = 0; i < QResultLayerREC.length; i++) {
                entities.removeById(QResultLayerREC[i].id);
            }
            // QResultLayerYHD.length=0;
        }
    } else if (type === 4) {
        //群测群防点-群众上报
        if (self.checked) {
            var hr = getRecordByType(0);
            showQresult(hr, true, type);

        } else {
            for (let i = 0; i < QResultLayerREC_0.length; i++) {
                entities.removeById(QResultLayerREC_0[i].id);
            }
            // QResultLayerYHD.length=0;
        }
    } else if (type === 5) {
        //群测群防点-日常巡查
        if (self.checked) {
            var hr = getRecordByType(1);
            showQresult(hr, true, type);

        } else {
            for (let i = 0; i < QResultLayerREC_1.length; i++) {
                entities.removeById(QResultLayerREC_1[i].id);
            }
            // QResultLayerYHD.length=0;
        }
    } else if (type == 10) {//倾斜数据1
        var TilesUrl = fromTypeGetTilesUrl(type);
        if (self.checked) {
            var obejct = Load3DTiles(TilesUrl);
            flyIntoObject(obejct);
        } else {
            Remove3DTiles(TilesUrl);
        }
    } else if (type == 11) {//倾斜数据2
        var TilesUrl = fromTypeGetTilesUrl(type);
        if (self.checked) {
            var obejct = Load3DTiles(TilesUrl);
            flyIntoObject(obejct);
        } else {
            Remove3DTiles(TilesUrl);
        }
    }
    else if (type == 12) {//倾斜数据3
        var TilesUrl = fromTypeGetTilesUrl(type);
        if (self.checked) {
            var obejct = Load3DTiles(TilesUrl);
            flyIntoObject(obejct);
        } else {
            Remove3DTiles(TilesUrl);
        }
    }
}
var QResultLayerXZQ = [];
var QResultLayerYHD = [];
var QResultLayerYFQ = [];
var QResultLayerQJ = [];
var QResultLayerQ = [];
var QResultLayerREC = [];//保存群测群防点对象
var QResultLayerREC_0 = [];//保存群测群防点对象(群众上报)
var QResultLayerREC_1 = [];//保存群测群防点对象(日常巡查)
function fromTypeGetTilesUrl(type) {
    var TilesUrl1 = fileBaseUrl + "/dzData1/tileset.json";
    var TilesUrl2 = fileBaseUrl + "/dzData2/tileset.json";
    var TilesUrl3 = fileBaseUrl + "/dzData3/tileset.json";
    if (type == 10) {
        return TilesUrl1;
    } else if (type == 11) {
        return TilesUrl2;
    } else if (type == 12) {
        return TilesUrl3;
    }
}
function showQresult(hr, isLayer, flag) {
    for (let i = 0; i < hr.length; i++) {
        var strgeom = hr[i].geom;
        var index1 = strgeom.indexOf('(');
        var geomType = strgeom.substring(0, index1);
        if (geomType == "POLYGON") {
            strgeom = strgeom.substring(index1 + 2, strgeom.length - 2);
            var pointTemp = [];
            var pointsTemp = strgeom.split(",");
            for (let j = 0; j < pointsTemp.length; j++) {
                var temp = pointsTemp[j].split(" ");
                var point = {x: temp[0], y: temp[1]};
                pointTemp.push(point);
            }
            if (isLayer) {
                var entity = DrawPloygon(hr[i].xzqmc, pointTemp, Cesium.Color.YELLOW.withAlpha(0.3), hr[i].xianMc, "xzq_" + hr[i].id);
                QResultLayerXZQ.push(entity);
            } else {

            }

        } else if (geomType == "MULTIPOLYGON") {
            strgeom = strgeom.substring(index1 + 3, strgeom.length - 3);
            strgeom = strgeom.replace(/\)\),\(\(/g, ",");
            var pointTemp = [];
            var pointsTemp = strgeom.split(",");
            for (let j = 0; j < pointsTemp.length; j++) {
                var temp = pointsTemp[j].split(" ");
                var point = {x: temp[0], y: temp[1]};
                pointTemp.push(point);
            }
            if (isLayer) {
                var entity = DrawPloygon(hr[i].xzqmc, pointTemp, Cesium.Color.YELLOW.withAlpha(0.3), hr[i].xianMc, "xzq_" + hr[i].id);
                QResultLayerXZQ.push(entity);
            } else {

            }

        } else if (geomType == "POINT") {
            strgeom = strgeom.substring(index1 + 1, strgeom.length - 1);
            var temp = strgeom.split(" ");
            var mURL = "";
            var name = "";
            var description = "";
            if (flag == 1) {
                mURL = "./static/images/yfq.png";
                name = hr[i].nd + "年度" + hr[i].zhType;
                description = hr[i].address;

            }
            else if (flag == 2) {
                mURL = "./static/images/yhd.png";
                name = hr[i].nd + "年度" + hr[i].zdMc;
                description = hr[i].zdWz;
            } else if (flag == 3) {
                mURL = "./static/images/rec.png";
                name = hr[i].hazardDetail;
                description = hr[i].street;
            } else if (flag === 4) {
                mURL = "./static/images/rec0.png";
                name = hr[i].hazardDetail;
                description = hr[i].street;
            } else if (flag === 5) {
                mURL = "./static/images/rec1.png";
                name = hr[i].hazardDetail;
                description = hr[i].street;
            }
            else if (flag == 6) {
                mURL = "./static/images/qj.png";
                name = hr[i].name;
                description = hr[i].name;

            }

            if (isLayer) {
                if (flag == 1) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerYFQ, "yfq_" + hr[i].id);
                }
                else if (flag == 2) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerYHD, "yhd_" + hr[i].id);
                }
                else if (flag == 3) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerREC, "rec_" + hr[i].id);
                }
                else if (flag == 4) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerREC_0, "rec0_" + hr[i].id);
                }
                else if (flag == 5) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerREC_1, "rec1_" + hr[i].id);
                } else if (flag == 6) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerQJ, "qj_" + hr[i].id);
                }


            } else {
                if (flag == 1) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerQ, "yfq_" + hr[i].id);
                }
                else if (flag == 2) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerQ, "yhd_" + hr[i].id);
                } else if (flag == 3) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerQ, "rec_" + hr[i].id);
                } else if (flag === 4) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerQ, "rec0_" + hr[i].id);
                } else if (flag === 5) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerQ, "rec1_" + hr[i].id);
                } else if (flag == 6) {
                    DrawBillboardByDegrees(name, temp[0], temp[1], mURL, description, QResultLayerQJ, "qj_" + hr[i].id);
                }
            }

        } else {
            continue;
        }
    }

    if (flag == 1 || flag == 2) {
        appendData(hr, flag);
    }
}


function showMapRMenu(x, y, entity) {
    RClick_entity = entity;
    if ($(".MAPrMenu:has(ul)").length) {//当有该权限才显示
        var menus = $('.MAPrMenu').children('ul').children('div').children('li');
        var FGline = $('.MAPrMenu').children('ul').children('div').children('div');
        var NChild = 0;
        //根据entity对象类型显示不同内容
        if (entity.id != undefined) {//普通对象
            if (entity) {
                var entityType = entity.id.dataid.split("_");
                if (entityType[0] == "xzq" || entityType[0] == "cx") {
                    menus.each(function () {
                        $(this).show();
                        FGline.eq(NChild).show();
                        NChild++;
                    });
                } else if ((entityType[0] == "yhd") || (entityType[0] == "yfq")) {
                    menus.each(function () {
                        if (this.innerText == "编辑" || this.innerText == "删除") {
                            $(this).show();
                            FGline.eq(NChild).show();
                            NChild++;
                        } else {
                            $(this).hide();
                            FGline.eq(NChild).hide();
                            NChild++;
                        }

                    });
                } else if (entityType[0] == "new") {
                    menus.each(function () {
                        if (this.innerText == "编辑" || this.innerText == "删除") {
                            $(this).hide();
                            FGline.eq(NChild).hide();
                            NChild++;

                        } else {
                            $(this).show();
                            FGline.eq(NChild).show();
                            NChild++;
                        }
                    });
                }
            }
        }
        else if (entity.content != undefined) {
            menus.each(function () {
                $(this).hide();
                FGline.eq(NChild).hide();
                NChild++;
            });
        }
        else {
            menus.each(function () {
                $(this).hide();
                FGline.eq(NChild).hide();
                NChild++;
            });
        }

        $('.MAPrMenu').css({"top": y + "px", "left": x + "px", "display": "inline"}); //设置右键菜单的位置、可见
    }
}

//隐藏右键菜单
function hideMapRMenu() {

    if ($('.MAPrMenu')) $('.MAPrMenu').css({"display": "none"}); //设置右键菜单不可见
}

function RMenuSave_yfq() {
    $("#uploaded-files").html("");
    document.getElementById("uploadPic").style.display = "block"; //显示
    document.getElementById("tijiao").style.display = "block"; //隐藏
    document.getElementById("addbtn").style.display = "block"; //隐藏
    document.getElementById("editbtn").style.display = "none"; //隐藏
    $("#addyfq")[0].reset();
    layui.form.render();
    layer.open({
        type: 1,
        shade: 0,
        area: ['70%', '80%'],
        size: 0,
        title: '填写地质灾害易发区信息',
        content: $('#addyfq')
    });

    // RClick_entity;
    var pointTemp = RClick_entity.id.position.getValue();
    var point = CartesianToDegrees(pointTemp);

    layui.use(['form'], function () {
        var form = layui.form;

        //监听提交
        form.on('submit(addyfq)', function (data) {

            var mygeom = 'POINT(' + point[0] + ' ' + point[1] + ')';
            var yfq = {
                szXian: data.field.szXian,
                szXiang: data.field.szXiang,
                address: data.field.address,
                zhType: data.field.zhType,
                wxH: data.field.wxH,
                wxJ: data.field.wxJ,
                wxR: data.field.wxR,
                azd: data.field.azd,
                wfYa: data.field.wfYa,
                zhMbk: data.field.zhMbk,
                bxMbk: data.field.bxMbk,
                cunFzr: data.field.cunFzr,
                tel1: data.field.tel1,
                zhenFzr: data.field.zhenFzr,
                tel2: data.field.tel2,
                xianFzr: data.field.xianFzr,
                tel3: data.field.tel3,
                bz: data.field.bz,
                geom: mygeom
            }
            var attaIds = getAttachmentIds();

            var yfqdata = JSON.stringify(yfq);
            var attas = JSON.stringify(attaIds);


            var hr = insertZhyfq(yfqdata, attas);
            if (hr > 0) {
                tempid = hr;


                DrawBillboardByDegrees(data.field.zhType, point[0], point[1], "./static/images/yfq.png",
                    data.field.address, QResultLayerYFQ, "yfq_" + hr);
                entities.removeById(RClick_entity.id.id);

                layer.msg('保存成功!', {
                    icon: 1,
                    time: 1000 //1.5秒关闭（如果不配置，默认是3秒）
                }, function () {
                    layer.closeAll();
                });

            }

            else {
                layer.msg("保存失败！");
            }

            hideMapRMenu();
            RClick_entity = null;

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


    });


}

function RMenuSave_yhd() {

    $("#yhd-uploaded-files").html("");
    document.getElementById("yhd-uploadPic").style.display = "block"; //显示
    document.getElementById("yhd-tijiao").style.display = "block"; //隐藏
    document.getElementById("yhd-addbtn").style.display = "block"; //隐藏
    document.getElementById("yhd-editbtn").style.display = "none"; //隐藏
    $("#addyhd")[0].reset();
    layui.form.render();

    layer.open({
        type: 1,
        shade: 0,
        area: ['70%', '80%'],
        size: 0,
        title: '填写地质灾害隐患点信息',
        content: $('#addyhd') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
    });


    layui.use(['form'], function () {
        var form = layui.form;

        //监听提交
        form.on('submit(addyhd)', function (data) {


            var pointTemp = RClick_entity.id.position.getValue();
            var point = CartesianToDegrees(pointTemp);
            var geom = 'POINT(' + point[0] + ' ' + point[1] + ')';

            var yhd = {
                szXian: data.field.szXian,
                szXiang: data.field.szXiang,
                szCun: data.field.szCun,
                szTun: data.field.szTun,
                zdMc: data.field.zdMc,
                zdWz: data.field.zdWz,
                yhdType: data.field.yhdType,
                fxDate: data.field.fxDate,
                ghFl: data.field.ghFl,
                yfYs: data.field.yfYs,
                yfYy: data.field.yfYy,
                wxDx: data.field.wxDx,
                wxR: data.field.wxR,
                wxCz: data.field.wxCz,
                xqJb: data.field.xqJb,
                bz: data.field.bz,
                jcy: data.field.jcy,
                tel1: data.field.tel1,
                cunFzr: data.field.cunFzr,
                tel2: data.field.tel2,
                xiangFzr: data.field.xiangFzr,
                tel3: data.field.tel3,
                xianFzr: data.field.xianFzr,
                tel4: data.field.tel4,
                geom: geom
            }
            var attaIds = getyhdAttachmentIds();

            var yhddata = JSON.stringify(yhd);
            var attas = JSON.stringify(attaIds);
            var hr = insertZhyhd(yhddata, attas);
            if (hr > 0) {
                tempid = hr;


                DrawBillboardByDegrees(data.field.zdMc, point[0], point[1], "./static/images/yhd.png",
                    data.field.zdWz, QResultLayerYHD, "yhd_" + hr);


                entities.removeById(RClick_entity.id.id);
                hideMapRMenu();
                RClick_entity = null;
                layer.msg('保存成功!', {
                    icon: 1,
                    time: 1000 //1.5秒关闭（如果不配置，默认是3秒）
                }, function () {
                    layer.closeAll();
                });

            }

            else {
                layer.msg("保存失败！");
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


    });


}

function RMenuEdit_node() {
    var entityType = RClick_entity.id.dataid.split("_");


    if (entityType[0] == "yfq") {
        tempid = entityType[1];
        document.getElementById("uploadPic").style.display = "block"; //显示
        document.getElementById("tijiao").style.display = "block"; //隐藏
        document.getElementById("addbtn").style.display = "none"; //隐藏
        document.getElementById("editbtn").style.display = "block"; //隐藏
        showYFQInfo(entityType[1], 2);


    } else if (entityType[0] == "yhd") {

        tempid = entityType[1];
        document.getElementById("yhd-uploadPic").style.display = "block"; //显示
        document.getElementById("yhd-tijiao").style.display = "block"; //隐藏
        document.getElementById("yhd-addbtn").style.display = "none"; //隐藏
        document.getElementById("yhd-editbtn").style.display = "block"; //隐藏
        showYHDInfo(entityType[1], 2);


    }
    // RClick_entity.id.description="";
    hideMapRMenu();
}

function RMenuDelete_node() {
    var entityType = RClick_entity.id.dataid.split("_");
    layer.confirm('是否确定删除？', {
        btn: ['不删除', '删除'] //按钮
    }, function () {
        layer.msg('没有删除！');
    }, function () {
        var hr = false;
        if (entityType[0] == "yhd") {
            hr = delete1Zhyhd(entityType[1]);
        } else if (entityType[0] == "yfq") {
            hr = delete1Zhyfq(entityType[1]);
        }
        if (hr) {
            entities.removeById(RClick_entity.id.id);
            layer.msg("删除成功！");
            layer.closeAll();
        }
        else
            layer.msg("删除失败！");
    });

    hideMapRMenu();
}
function deleteRow(id) {
    $("#option" + id).remove();
}
function getAttachmentIds() {
    var ids = new Array();
    $("#uploaded-files tr").each(function () {
        ids.push($(this).attr("data-id"));
    });
    return ids;
}
function getyhdAttachmentIds() {
    var ids = new Array();
    $("#yhd-uploaded-files tr").each(function () {
        ids.push($(this).attr("data-id"));
    });
    return ids;
}
function gettubiaodata() {

    var objS = document.getElementById("dropmenu");
    var field = objS.options[objS.selectedIndex].value;
    var legendData = [];
    var seriesData = [];
    for (var i = 0; i < tubiaodata.length; i++) {

        var flag = true;
        if (seriesData.length > 0) {
            for (var j = 0; j < seriesData.length; j++) {

                if (tubiaodata[i][field] != undefined) {

                    if (tubiaodata[i][field] == seriesData[j].name) {
                        flag = false;
                    }
                }
            }
        }


        if (flag) {
            var value = 0;
            for (var k = 0; k < tubiaodata.length; k++) {
                if (tubiaodata[k][field] == tubiaodata[i][field]) {
                    value = value + 1;
                }

            }

            legendData.push(tubiaodata[i][field]);
            seriesData.push({
                name: tubiaodata[i][field],
                value: value


            });
        }


    }
    return {
        legendData: legendData,
        seriesData: seriesData,
    };

}

function tianchongtubiao(data) {
    var myChart = echarts.init(document.getElementById('bingtu'));
    option = {
        title: {
            text: '',
            subtext: '',
            left: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
            type: 'scroll',
            orient: 'vertical',
            right: 10,
            top: 20,
            bottom: 20,
            data: data.legendData,
        },
        series: [
            {
                name: '',
                type: 'pie',
                radius: '55%',
                center: ['40%', '60%'],
                data: data.seriesData,
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };

    myChart.setOption(option);
}

function tianchongyhd(xq) {

    $('#yhd-szXian').val(xq.szXian);
    $('#yhd-szXiang').val(xq.szXiang);
    $('#yhd-szCun').val(xq.szCun);
    $('#yhd-szTun').val(xq.szTun);
    $('#yhd-zdMc').val(xq.zdMc);
    $('#yhd-zdWz').val(xq.zdWz);
    $('#yhd-yhdType').val(xq.yhdType);
    $('#yhd-fxDate').val(xq.fxDate);
    $('#yhd-ghFl').val(xq.ghFl);
    $('#yhd-yfYs').val(xq.yfYs);
    $('#yhd-yfYy').val(xq.yfYy);
    $('#yhd-wxDx').val(xq.wxDx);
    $('#yhd-wxR').val(xq.wxR);
    $('#yhd-wxCz').val(xq.wxCz);
    $('#yhd-xqJb').val(xq.xqJb);
    $('#yhd-bz').val(xq.bz);
    $('#yhd-jcy').val(xq.jcy);
    $('#yhd-tel1').val(xq.tel1.replace('.0', ''));
    $('#yhd-cunFzr').val(xq.cunFzr);
    $('#yhd-tel2').val(xq.tel2.replace('.0', ''));
    $('#yhd-xiangFzr').val(xq.xiangFzr);
    $('#yhd-tel3').val(xq.tel3.replace('.0', ''));
    $('#yhd-xianFzr').val(xq.xianFzr);
    $('#yhd-tel4').val(xq.tel4.replace('.0', ''));

}


function tianchong(xq) {

    $('#szXian').val(xq.szXian);
    $('#zhType').val(xq.zhType);
    $('#szXiang').val(xq.szXiang);
    $('#address').val(xq.address);
    $('#wxH').val(xq.wxH);
    $('#wxJ').val(xq.wxJ);
    $('#wxR').val(xq.wxR);
    $('#azd').val(xq.azd);
    $('#wfYa').val(xq.wfYa);
    $('#zhMbk').val(xq.zhMbk);
    $('#cunFzr').val(xq.cunFzr);
    $('#tel1').val(xq.tel1.replace('.0', ''));
    $('#zhenFzr').val(xq.zhenFzr);
    $('#tel2').val(xq.tel2.replace('.0', ''));
    $('#xianFzr').val(xq.xianFzr);
    $('#tel3').val(xq.tel3.replace('.0', ''));
    $('#bz').val(xq.bz);
}

function gettubiaochushihuadata(field) {

    var legendData = [];
    var seriesData = [];
    for (var i = 0; i < tubiaodata.length; i++) {
        var value;
        value = 1;
        legendData.push(tubiaodata[i][field]);
        seriesData.push({
            name: tubiaodata[i][field],
            value: value
        });

    }
    return {
        legendData: legendData,
        seriesData: seriesData,
    };

}
function showYFQInfo(id, type) {
    if (id == undefined) {
        id = tempid;
    }

    var data = getInfoByZhyfqid(id);

    layer.open({
        type: 1,
        maxmin: true,
        shade: 0,
        area: ['70%', '80%'],
        size: 0,
        title: '地质灾害易发区信息',
        content: $('#addyfq') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
    });
    $("#uploaded-files").html("");
    $.ajax({
        url: "/geoZhyfq/getFileByZhyfqid?id=" + id,
        type: 'GET',
        dataType: "json",
        async: false,
        success: function (files) {
            if (files.length > 0) {
                for (var j = 0; j < files.length; j++) {
                    if (type == 1) {
                        $("#uploaded-files").append(
                            $("<tr id='option" + files[j].id + "' data-id='" + files[j].id + "'/>")
                                .append($('<td/>').html("<img class='layui-upload-img' id='pic" + files[j].id + "' alt='" + files[j].fileName + "' src='/upload/downloadFile/" + files[j].id + "'  >"))
                        );
                    }
                    if (type == 2) {
                        $("#uploaded-files").append(
                            $("<tr id='option" + files[j].id + "' data-id='" + files[j].id + "'/>")
                                .append($('<td/>').html("<img class='layui-upload-img' id='pic" + files[j].id + "' alt='" + files[j].fileName + "' src='/upload/downloadFile/" + files[j].id + "'  >"))
                                .append($('<td/>').html("<a onclick='deleteRow(" + files[j].id + ")'>删除</a>"))
                        );

                    }

                }
            }


        },
        error: function () {

        },

    });

    tianchong(data);
    var form = layui.form;
    form.render();

}
function showYHDInfo(id, type) {

    if (id == undefined) {
        id = tempid;
    }

    var data = getInfoByidZhyhd(id);

    layer.open({
        type: 1,
        maxmin: true,
        shade: 0,
        area: ['70%', '80%'],
        size: 0,
        title: '地质灾害隐患点信息',
        content: $('#addyhd') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
    });
    $("#yhd-uploaded-files").html("");
    $.ajax({
        url: "/geoZhyhd/getFileByZhyhdid?id=" + id,
        type: 'GET',
        dataType: "json",
        async: false,
        success: function (files) {
            if (files.length > 0) {
                for (var j = 0; j < files.length; j++) {
                    if (type == 1) {
                        $("#yhd-uploaded-files").append(
                            $("<tr id='option" + files[j].id + "' data-id='" + files[j].id + "'/>")
                                .append($('<td/>').html("<img class='layui-upload-img' id='pic" + files[j].id + "' alt='" + files[j].fileName + "' src='/upload/downloadFile/" + files[j].id + "'  >"))
                        );
                    }
                    if (type == 2) {
                        $("#yhd-uploaded-files").append(
                            $("<tr id='option" + files[j].id + "' data-id='" + files[j].id + "'/>")
                                .append($('<td/>').html("<img class='layui-upload-img' id='pic" + files[j].id + "' alt='" + files[j].fileName + "' src='/upload/downloadFile/" + files[j].id + "'  >"))
                                .append($('<td/>').html("<a onclick='deleteRow(" + files[j].id + ")'>删除</a>"))
                        );

                    }

                }
            }


        },
        error: function () {

        },

    });

    tianchongyhd(data);
    var form = layui.form;
    form.render();

}

function showAllInfo(data) {
    var temp = data.split("_");
    if (temp[0] == "yhd") {
        document.getElementById("yhd-uploadPic").style.display = "none"; //显示
        document.getElementById("yhd-tijiao").style.display = "none"; //隐藏
        document.getElementById("yhd-addbtn").style.display = "none"; //隐藏
        document.getElementById("yhd-editbtn").style.display = "none"; //隐藏
        showYHDInfo(temp[1], 1);
    } else if (temp[0] == "yfq") {
        document.getElementById("uploadPic").style.display = "none"; //显示
        document.getElementById("tijiao").style.display = "none"; //隐藏
        document.getElementById("addbtn").style.display = "none"; //隐藏
        document.getElementById("editbtn").style.display = "none"; //隐藏
        showYFQInfo(temp[1], 1);
    }

    else if (temp[0] == "qj") {
        showQJ(temp[1], "全景查看");
    }
    else if (temp[0] == "rec" || temp[0] == "rec0" || temp[0] == "rec1") {


        $.ajax({
            url: "/recordDO/getRecordById?id=" + temp[1],
            type: 'GET',
            dataType: "json",
            async: false,
            success: function (res) {
                layer.open({
                    type: 1,
                    title: "群测群防点详情",
                    area: ['80%', '80%'],
                    content: $('#rec')
                });

                tianchongRec(res);
                var form = layui.form;
                form.render();

                /* 获取文件 */
                $.ajax({
                    url: "/recordDO/getFilesByRecordId?id=" + temp[1],
                    type: 'GET',
                    dataType: "json",
                    success: function (data) {

                        $("#pic").html("");
                        if (data.length > 0) {
                            for (var j = 0; j < data.length; j++) {
                                $("#pic").append("<li><img src='/upload/downloadFile/" + data[j].id +
                                    "'    data-original='/upload/downloadFile/" + data[j].id + "'   alt='" +
                                    data[j].fileName + "'   /></li>");

                            }
                        }
                        var viewer = new Viewer(document.getElementById('pic'), {
                            toolbar: true, //显示工具条
                            viewed() {
                                viewer.zoomTo(1); // 图片显示比例 75%
                            },
                            show: function () { // 动态加载图片后，更新实例
                                viewer.update();
                            },
                        });

                    },
                    error: function () {

                    },

                });


            },


        });


    }


}
//显示全景
function showQJ(fileid, name) {
    var lIndex = layer.open({
        type: 2,
        title: name,
        shadeClose: false,
        shade: 0.5,
        maxmin: true,
        area: ['800px', '600px'],
        content: fileBaseUrl + "/dzQJ/" + fileid
    });
}
//全局搜索
function SearchAll() {
    layer.open({
        type: 1,
        title: '全局搜索',
        shade: false,
        offset: 'rb',
        maxmin: true,
        closeBtn: 1,
        area: ['100%', '48%'],
        content: $('#fenxitable'), cancel: function () {
            deleteAllLS();
        }
    });
    document.getElementById("resultdiv").style.display = "none";
    document.getElementById("searchdiv").style.display = "block"; //隐藏
}

function qingchu() {
    $("#keywords").val("");
    /*    layui.use(['table'], function () {
     var table = layui.table;
     table.reload({
     elem: '#res-yhd'
     });
     table.reload({
     elem: '#res-yfq'
     });

     });*/
    deleteAllLS();
}
function tianchongRec(data) {
    /* 整合:处理人姓名应该获取 */
    $('#operatorName').val(data.operatorName);
    $('#type').val(data.type);
    $('#status').val(data.status);
    $('#userPhone').val(data.userPhone);
    $('#userName').val(data.userName);
    $('#city').val(data.city);
    $('#district').val(data.district);
    $('#street').val(data.street);
    $('#streetNumber').val(data.streetNumber);
    $('#hazardType').val(data.hazardType);
    $('#hazardLevel').val(data.hazardLevel);
    $('#hazardScale').val(data.hazardScale);
    $('#hazardStatus').val(data.hazardStatus);
    $('#hazardDetail').val(data.hazardDetail);
    $('#feedback').val(data.feedback);
    $('#inspectionStatus').val(data.inspectionStatus);
    $('#inspectionDetail').val(data.inspectionDetail);
    $('#remark').val(data.remark);
    $('#id').val(data.id);
    $('#createTime').val(data.createTime);
}
function searchBykeywords() {

    var keywords = $("#keywords").val();
    if (keywords == null || keywords.trim().length == 0) {
        layer.msg("搜索条件不能为空!");
        return;
    }
    document.getElementById("resultdiv").style.display = "block";
    document.getElementById("searchdiv").style.display = "block"; //隐藏

    var loading = getZhyfqByKeywords(keywords);
    getZhyhdByKeywords(keywords, loading);

}
function appendData(hr, flag) {
    layui.use('table', function () {

        if (flag == 1) {

            var cols = [[
                {field: "id", title: "ID", minWidth: 150},
                {field: "szXian", title: "县(区)", minWidth: 150},
                {field: "szXiang", title: "乡（镇、街道办）", minWidth: 150},
                {field: "address", title: "地址", minWidth: 150},
                {field: "zhType", title: "易发灾种", minWidth: 150},
                {field: "wxH", title: "威胁房屋(户)", minWidth: 150},
                {field: "wxJ", title: "威胁房屋(间)", minWidth: 150},
                {field: "wxR", title: "威胁人口（人）", minWidth: 150},
                {field: "azd", title: "避灾安置点", minWidth: 150},
                {field: "wfYa", title: "有无应急预案表", minWidth: 150},
                {field: "zhMbk", title: "防灾明白卡（份）", minWidth: 150},
                {field: "bxMbk", title: "避险明白卡（份）", minWidth: 150},
                {field: "cunFzr", title: "村(社区)负责人", minWidth: 150},
                {field: "tel1", title: "电话号码", minWidth: 150},
                {field: "zhenFzr", title: "乡(镇/街道办)负责人", minWidth: 150},
                {field: "tel2", title: "电话号码", minWidth: 150},
                {field: "xianFzr", title: "县（区）负责人", minWidth: 150},
                {field: "tel3", title: "所在乡", minWidth: 150},
                {field: "bz", title: "备注", minWidth: 150}]];


            table.render({
                elem: "#res-yfq",
                cols: cols,
                data: hr,
                toolbar: '#toolbar'
                , defaultToolbar: ['filter', 'exports', 'print', {
                    title: '分析' //标题
                    , layEvent: 'fenxi' //事件名，用于 toolbar 事件中使用
                    , icon: 'layui-icon-engine' //图标类名
                }], skin: 'line' //表格风格
                ,
                even: true
                ,
                page: true //是否显示分页
                ,
                limits: [5, 7, 10]
                ,
                limit: 5 //每页默认显示的数量

            });
            table.on('rowDouble(yfqfilter)', function (obj) {

                var arr = obj.data.geom.split(' ');
                var lat = arr[0].substring(6, arr[0].length)
                var lng = arr[1].substring(0, arr[1].length - 1);
                DrawBillboardByDegrees(obj.data.zhType, lat, lng, "./static/images/points.png",
                    obj.data.address, QResultLayerQ, "yfq_" + obj.data.id);

            });

        } else if (flag == 2) {

            var cols = [[
                {field: "id", title: "ID", minWidth: 150},
                {field: "szXian", title: "县(区)", minWidth: 150},
                {field: "szXiang", title: "乡（镇、街道办）", minWidth: 150},
                {field: "szCun", title: "村（社区）", minWidth: 150},
                {field: "szTun", title: "屯", minWidth: 150},
                {field: "zdMc", title: "灾点名称", minWidth: 150},
                {field: "zdWz", title: "灾点位置", minWidth: 150},
                {field: "yhdType", title: "隐患点类型", minWidth: 150},
                {field: "fxDate", title: "发现时间", minWidth: 150},
                {field: "ghFl", title: "规模方量（m3）", minWidth: 150},
                {field: "yfYs", title: "引发因素", minWidth: 150},
                {field: "yfYy", title: "引发原因", minWidth: 150},
                {field: "wxR", title: "威胁人数（人）", minWidth: 150},
                {field: "wxCz", title: "威胁财产（万元）", minWidth: 150},
                {field: "xqJb", title: "险情级别", minWidth: 150},
                {field: "jcy", title: "监测员（群测人员）", minWidth: 150},
                {field: "tel1", title: "电话号码", minWidth: 150},
                {field: "cunFzr", title: "村级负责人", minWidth: 150},
                {field: "tel2", title: "电话号码", minWidth: 150},
                {field: "xiangFzr", title: "乡级负责人", minWidth: 150},
                {field: "tel3", title: "电话号码", minWidth: 150},
                {field: "xian_fzr", title: "县级负责人", minWidth: 150},
                {field: "tel4", title: "电话号码", minWidth: 150},
                {field: "bz", title: "备注", minWidth: 150},

            ]];


            table.render({
                elem: "#res-yhd",
                cols: cols,
                data: hr,
                toolbar: '#toolbar'
                , defaultToolbar: ['filter', 'exports', 'print', {
                    title: '分析' //标题
                    , layEvent: 'fenxi' //事件名，用于 toolbar 事件中使用
                    , icon: 'layui-icon-engine' //图标类名
                }],
                skin: 'line' //表格风格
                ,
                even: true
                ,
                page: true //是否显示分页
                ,
                limits: [5, 7, 10]
                ,
                limit: 5 //每页默认显示的数量

            });
            table.on('rowDouble(yhdfilter)', function (obj) {

                var arr = obj.data.geom.split(' ');
                var lat = arr[0].substring(6, arr[0].length)
                var lng = arr[1].substring(0, arr[1].length - 1);

                DrawBillboardByDegrees(obj.data.zdMc, lat, lng, "./static/images/points.png",
                    obj.data.zdWz, QResultLayerQ, "yhd_" + obj.data.id);

            });
        }
        //监听事件
        //监听事件
        table.on('toolbar(yhdfilter)', function (obj) {

            $('#dropmenu').html("");

            if (obj.event === 'daochu') { //提供工具栏导出按钮的点击事件
                var res = hr;
                if (res[0].id != 'ID') {
                    res.unshift({
                        id: 'ID',
                        szXian: '县(区)',
                        szXiang: '乡（镇、街道办）',
                        szCun: '村（社区）',
                        szTun: '屯',
                        zdMc: '灾点名称',
                        zdWz: '灾点位置',
                        yhdType: '隐患点类型',
                        fxDate: '发现时间',
                        ghFl: '规模方量（m3）',
                        yfYs: '引发因素',
                        yfYy: '引发原因',
                        wxDx: '威胁对象',
                        wxR: '威胁人数（人）',
                        wxCz: '威胁财产（万元）',
                        xqJb: '险情级别',
                        jcy: '监测员（群测人员）',
                        tel1: '电话号码',
                        cunFzr: '村级负责人',
                        tel2: '电话号码',
                        xiangFzr: '乡级负责人',
                        tel3: '电话号码',
                        xianFzr: '县级负责人',
                        tel4: '电话号码',
                        bz: '备注',
                        geom: '坐标'
                    });
                }

                LAY_EXCEL.exportExcel(res, '隐患点数据.xlsx', 'xlsx')
            }


            if (obj.event == 'fenxi') {
                tubiaodata = obj.config.data;
                var cols = obj.config.cols[0];
                for (var i = 0; i < cols.length; i++) {

                    $('#dropmenu').append('<option value="' + cols[i].field + '">' + cols[i].title + '</option>');


                }
                layer.open({
                    type: 1,
                    title: '数据汇总',
                    shade: false,
                    maxmin: true,
                    closeBtn: 1,
                    area: ['60%', '60%'],
                    content: $('#tubiao'), cancel: function () {

                    }
                });
                var data = gettubiaochushihuadata(cols[0].field);
                tianchongtubiao(data);

            }
        });

        //监听事件
        table.on('toolbar(yfqfilter)', function (obj) {

            $('#dropmenu').html("");
            if (obj.event === 'export') { //提供工具栏导出按钮的点击事件
                var result = hr;
                if (result[0].id != 'ID') {
                    result.unshift({
                        id: 'ID',
                        szXian: '县(区)',
                        szXiang: '乡（镇、街道办）',
                        address: '地理位置',
                        zhType: '易发灾种',
                        wxH: '威胁房屋-户',
                        wxJ: '威胁房屋-间',
                        wxR: '地理位置',
                        address: '威胁人口（人）',
                        azd: '避灾安置点',
                        wfYa: '有无应急预案表',
                        zhMbk: '防灾明白卡（份）',
                        bxMbk: '避险明白卡（份）',
                        cunFzr: '村(社区)负责人',
                        tel1: '地理位置',
                        zhenFzr: '电话号码',
                        address: '乡(镇/街道办)负责人',
                        tel2: '电话号码',
                        xianFzr: '县（区）负责人',
                        tel3: '电话号码',
                        bz: '备注',
                        geom: '坐标'
                    });
                }

                LAY_EXCEL.exportExcel(result, '易发区数据.xlsx', 'xlsx')
            }


            if (obj.event == 'fenxi') {
                tubiaodata = obj.config.data;
                var cols = obj.config.cols[0];
                for (var i = 0; i < cols.length; i++) {

                    $('#dropmenu').append('<option value="' + cols[i].field + '">' + cols[i].title + '</option>');


                }
                layer.open({
                    type: 1,
                    title: '数据汇总',
                    shade: false,
                    maxmin: true,
                    closeBtn: 1,
                    area: ['60%', '60%'],
                    content: $('#tubiao'), cancel: function () {

                    }
                });
                var data = gettubiaochushihuadata(cols[0].field);
                tianchongtubiao(data);

            }
        });

    });
}

